<?php session_start();
ob_start();
	?>

<?php 
	require '../src/facebook.php';
	include_once ("configs/config.php");     //���ò���
	require 'common/facebook_util.php';
     
	#��֤�û���Ȩ
    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream,friends_education_history";

    $signed_request = $_REQUEST["signed_request"];

    $data = parse_signed_request($signed_request, $app_secret);

    if (empty($data["user_id"])) {
           echo("<script> top.location.href='" . $auth_url . "'</script>");
    } 
   
    $user_id = $data["user_id"];
    $cookie_value = auth_encode($user_id);
	setcookie("iridescent", $cookie_value, time()+7200); /* 有效期 2个小时 */ 
	ob_end_flush();
	
	$facebook = new Facebook(array(
	'appId'  => '231095003576729',
	'secret' => $app_secret,
	'cookie' => true,
	));

	$method = $data["user_id"] . '/friends';

	$friendslist = $facebook->api($method);
	foreach($friendslist['data'] as $v){
		print_r ('<b>' . $v['id'] . $v['name'] . '</b>' . '<br>' );
		$friend_apistr = $v['id'];
		$friend_info = $facebook->api($friend_apistr);
		if($friend_info['education'] != null)
		{
			foreach ($friend_info['education'] as $edu)
			{
				print ($edu['school']['name'] . '<br>');
			}
		}
	}
?>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
</head>
<body>

</body>
</html>
